package com.yunmai.steplibrary;

import android.os.RemoteException;
import java.util.concurrent.CopyOnWriteArrayList;

public class StepCounterBinder extends IStepCounterBinder.Stub{
  CopyOnWriteArrayList<IStepCallBack> list = null;
  public StepCounterBinder(){
    list = new CopyOnWriteArrayList<>();
  }

  @Override public int getResult() throws RemoteException {
    return 0;
  }

  public void notifyCallBack(int allCount,int currentCount){
    try {
      for(IStepCallBack binder:list){
          binder.callBack(allCount,currentCount);
      }
    } catch (RemoteException e) {
      e.printStackTrace();
    }
  }

  @Override public void registerCallBack(IStepCallBack callback) throws RemoteException {
    if(!list.contains(callback)) {
      list.add(callback);
    }
  }

  @Override public void unRegisterCallBack(IStepCallBack callback) throws RemoteException {
    if(list.contains(callback)){
      list.remove(callback);
    }
  }
}
